package com.reekr.a5t.web.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

public class BaseController {

	@ExceptionHandler(Throwable.class)
	public ModelAndView handleIOException(IOException ex, HttpServletRequest request) {
		System.out.println("出错了");
		ModelAndView mv = new ModelAndView("/error.ftl");
		mv.addObject("key", "value");
		return mv;
	}
	
	/**
	 * ajax锟斤拷锟斤拷谋锟� json
	 * @param response
	 * @param txt
	 */
	public void outputJson(HttpServletResponse response, String txt) {
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
			out.print(txt);
			out.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			out.close();
		}
	}
	
}

